using UnityEngine;

namespace BridgeShips.AI
{
    public class ShipLinkingFinish : Action
    {
		[SerializeField]
		[Clamp(0f, 100f)]
		private float m_MinBreakDistance = 3.0f;
    
        private Vector3 m_BreakPosition;

        public override void OnStart(AIShip ship)
        {
            m_Priority = 12;
            m_IsInterruptable = true;
            m_RepeatType = ET.ActionRepeatType.Single;

			Preconditions.Add(HelpStrings.AI.IS_SHIP_LINKED, true);

			Effects.Add(HelpStrings.AI.IS_SHIP_LINKED, true);
        }

        public override bool CanActivate(AIShip ship) 
		{
			if(ship.Settings.Detection.HaveLinked())
			{
				Vector3 shipPos = ship.transform.position;
				Vector3 targetPos = ship.Settings.Detection.GetRandomTarget().Position();
				return (shipPos - targetPos).magnitude < m_MinBreakDistance;
			}

			return false;
		}

        public override void Activate(AIShip ship)
        {
           
        }

        public override void OnUpdate(AIShip ship) 
		{
			Vector3 aiPos = ship.transform.position;

       
		}

		public override void OnDeactivation(AIShip ship)
		{

		}

        public override bool StillValid(AIShip ship) 
		{
			return ship.Settings.Detection.HasTarget();
		}

        public override bool IsDone(AIShip ship)
		{
			return !ship.Settings.Detection.HasTarget();
		}
    }
}